package com.cqemme.comm.po;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.StringUtils;

/**
 * 
 * ClassName:RequestInfo
 * @Description:
 * TODO
 * Company:EM ChongQing SCIENCE And TECHNOLOGY CO.LTD
 * date:2019-06-05
 * @Author:Tommy
 *
 * 
 * ******************************************************
 * HISTORY
 * 2019-06-05 add by Tommy
 * 
 *
 */
public class RequestInfo {
	//page number
		private Integer pageNum;
		//size by page
		private Integer pageSize;
		//order field info
		private String orderFieldInfo;
		//ASC,DESC
		private String orderBy;
		
		//JSON
		private String queryWhere;

		public Integer getPageNum() {
			if(pageNum==null) {
				pageNum=1;
			}
			return pageNum;
		}

		public void setPageNum(Integer pageNum) {
			this.pageNum = pageNum;
		}

		public Integer getPageSize() {
			if(pageSize==null) {
				pageSize=20;
			}
			return pageSize;
		}

		public void setPageSize(Integer pageSize) {
			this.pageSize = pageSize;
		}

		public String getQueryWhere() {
			return this.queryWhere;	
		}
		
		@SuppressWarnings({ "rawtypes", "unchecked" })
		public Object getQueryWhereByObj(Class cls) {
			Object ret = null;
			if(StringUtils.isNotBlank(queryWhere)) {
				ObjectMapper mapper=new ObjectMapper();
				try {
					ret = mapper.readValue(queryWhere, cls);
				} catch (Exception e) {
				}
			}
			return 	ret;	
		}

		public void setQueryWhere(String queryWhere) {
			this.queryWhere = queryWhere;
		}

		public String getOrderBy() {
//			String ret = EnumOrder.ASC.getOrderValue();
//			if(!StringUtils.isBlank(this.orderBy)) {
//				ret = this.orderBy;
//			}
			
			return  this.orderBy;
		}

		public void setOrderBy(String orderBy) {
			this.orderBy = orderBy;
			
		}
		
		public String getOrderFieldInfo() {
			return orderFieldInfo;
		}

		public void setOrderFieldInfo(String orderFieldInfo) {
			this.orderFieldInfo = orderFieldInfo;
		}
		
		public String getOrderBySQL() {
			String ret = null;
			
				if(!StringUtils.isBlank(orderBy)) {
					if(!StringUtils.isBlank(orderFieldInfo)) {
						ret = orderFieldInfo;
						ret += " ";
						ret += orderBy;
					}
				}
			
			return ret;
		}
}
